import request from '@/utils/request'

export function tree() {
  return request({
    url: '/api/sys/dept/list',
    method: 'post',
    data: {}
  })
}

export function roleList(form) {
  return request({
    url: '/api/sys/role/list',
    method: 'post',
    data: {
      dept_code: form.dept_code
    }
  })
}

export function save(form) {
  return request({
    url: '/api/sys/role/save',
    method: 'post',
    data: {
      dept_code: form.dept_code,
      role_name: form.role_name,
      role_order: form.role_order,
      role_desc: form.role_desc
    }
  })
}

export function update(form) {
  return request({
    url: '/api/sys/role/update',
    method: 'post',
    data: {
      role_id: form.role_id,
      dept_code: form.dept_code,
      role_name: form.role_name,
      role_order: form.role_order,
      role_desc: form.role_desc
    }
  })
}

export function menuTree(role_id) {
  return request({
    url: '/api/sys/role/menu/tree',
    method: 'post',
    data: {
      role_id: role_id
    }
  })
}

// export function menuByRole(role_id) {
//   return request({
//     url: '/api/sys/role/menu/now',
//     method: 'post',
//     data: {
//       role_id: role_id
//     }
//   })
// }

export function saveMenu(form) {
  return request({
    url: '/api/sys/role/menu/save',
    method: 'post',
    data: {
      role_id: form.role_id,
      menu_ids: form.menu_ids
    }
  })
}

// export function delMenu(form) {
//   return request({
//     url: '/api/sys/role/menu/delete',
//     method: 'post',
//     data: {
//       role_id: form.role_id,
//       menu_id: form.menu_id
//     }
//   })
// }

export function permTree(form) {
  return request({
    url: '/api/sys/role/perm/tree',
    method: 'post',
    data: {
      role_id: form.role_id,
      app_id_ex: form.app_id_ex,
      perm_name: form.perm_name,
      perm_desc: form.perm_desc,
      action_key: form.action_key,
      controller: form.controller,
      controller_name: form.controller_name
    }
  })
}

export function savePerm(form) {
  return request({
    url: '/api/sys/role/perm/save',
    method: 'post',
    data: {
      role_id: form.role_id,
      perm_id: form.perm_id
    }
  })
}

export function delPerm(form) {
  return request({
    url: '/api/sys/role/perm/delete',
    method: 'post',
    data: {
      role_id: form.role_id,
      perm_id: form.perm_id
    }
  })
}
